<?php

/**
 * CelebrityModule actions.
 *
 * @package    ieasys
 * @subpackage CelebrityModule
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class celebrityActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        //$this->forward('default', 'module');
    }

    /**
     * ��ϸ��Ϣ
     * param id ��Ϣid
     * param cataloged   �����
     * @return void
     */
    public function executeDetail(sfWebRequest $request) //sfWebRequest $request
    {
        $celebrityid = $request->getParameter('celebrityId');
        if (null == $celebrityid || "" == $celebrityid)
            $celebrityid = 1000;
        $execsql = Doctrine_Core::getTable("celebrity")->createQuery('c')->where("celebrity_id='" . $celebrityid . "'");
        /*$catalogid= $request->getParameter('catalogId');
        if(null==$catalogid||""==$catalogid)
            $catalogid=1000;
        $execsql=$execsql->andWhere("catalog_id='".$catalogid."'");*/
        $celebritys = $execsql->execute();
        $this->catalogId = null;
        $this->celebrity = new Celebrity();
        foreach ($celebritys as $celebrity)
        {
            $this->celebrity = $celebrity;
            $this->catalogId = $celebrity->getCatalogId();
            $this->response->setTitle($celebrity->getName() . "_明星百科_" . $celebrity->getCatalog()->getDescription() . "_" . sfConfig::get("app_site_name"));
            $this->response->setKeywords($celebrity->getKeyword());
            break;
        }
    }

    public function executeCover(sfWebRequest $request)
    {
        $this->catalogId = $request->getParameter('catalogId');
        if (null == $this->catalogId && "" == $this->catalogId)
            $this->catalogId = 1000;

        $catalog = Doctrine_Core::getTable("Catalog")->createQuery()
                ->where("catalog_id=?", $this->catalogId)
                ->execute()
                ->getFirst();
        $this->response->setTitle("明星百科_" . $catalog->getDescription() . "_" . sfConfig::get("app_site_name"));

        //        $query = @Doctrine_Core::getTable("Celebrity")->createQuery()
        //                ->andWhere("c_type = '". Constants::$_CELEBRITY_TYPE_BAND."'")
        //                ->orderBy("hit_i+hit_mask_i desc");
        //        $query = Doctrine_Core::getTable("Celebrity")->createQuery('c')
        //                ->where("c.c_type !='" . Constants::$_CELEBRITY_TYPE_BAND . "'")
        //                ->andWhere("c.sex = '" . Constants::$_CELEBRITY_SEX_MALE . "'")
        //                ->orderBy("c.hit_i+c.hit_mask_i desc");
        //        $query = @Doctrine_Core::getTable("Celebrity")->createQuery()
        //                ->where("c_type != '". Constants::$_CELEBRITY_TYPE_BAND."'")
        //                ->andWhere("sex = '". Constants::$_CELEBRITY_SEX_FEMALE."'")
        //                ->orderBy("hit_i+hit_mask_i desc");

        $this->bands = Doctrine_Core::getTable("Celebrity")->createQuery('c')
                ->addWhere('c.c_type = ?', Constants::$_CELEBRITY_TYPE_BAND)
                ->addWhere('c.catalog_id = ?', $this->catalogId)
                ->addWhere('c.status_id=?', 1005)
                ->orderBy('c.hit_i+c.hit_mask_i desc')->limit(6)
                ->execute();
        $this->males = Doctrine_Core::getTable("Celebrity")->createQuery('c')
                ->addWhere('c.c_type != ?', Constants::$_CELEBRITY_TYPE_BAND)
                ->addWhere('c.sex = ?', Constants::$_CELEBRITY_SEX_MALE)
                ->addWhere('c.catalog_id = ?', $this->catalogId)
                ->addWhere('c.status_id=?', 1005)
                ->orderBy('c.hit_i+c.hit_mask_i desc')
                ->limit(6)->execute();
        $this->females = Doctrine_Core::getTable("Celebrity")->createQuery('c')
                ->addWhere('c.c_type != ?', Constants::$_CELEBRITY_TYPE_BAND)
                ->addWhere('c.sex = ?', Constants::$_CELEBRITY_SEX_FEMALE)
                ->addWhere('c.catalog_id = ?', $this->catalogId)
                ->addWhere('c.status_id=?', 1005)
                ->orderBy('c.hit_i+c.hit_mask_i desc')
                ->limit(6)->execute();


    }


    public function executeList(sfWebRequest $request) //sfWebRequest $request
    {
        $this->catalogId = $request->getParameter('catalogId');
        $this->recordCount = $request->getParameter('recordCount');
        $this->currentPage = $request->getParameter('currentPage');
        $this->link = $request->getParameter('link');

        $sex = $request->getParameter('sex');
        $type = $request->getParameter('type');
        if (null == $this->catalogId && "" == $this->catalogId)
            $this->catalogId = 1000;
        if (null == $this->recordCount || "" == $this->recordCount)
            $this->recordCount = 21;
        if (null == $this->currentPage || "" == $this->currentPage)
            $this->currentPage = 1;
        if (null == $this->link || "" == $this->link)
            $this->link = 1;
        $catalog = Doctrine_Core::getTable("Catalog")->find($this->catalogId);
        $this->response->setTitle("明星百科_" . $catalog->getDescription() . "_" . sfConfig::get("app_site_name"));

        $query = Doctrine_Query::create()->from("celebrity c")
                ->where('catalog_id=' . $this->catalogId)->andWhere('c.status_id=1005');

        if (null != $this->link && "" != $this->link && 1 != $this->link) {
            if ($this->link == 'ot')
                $query = $query->andWhereNotIn('capital_letter', Constants::$ALPHABET);
            else
                $query = $query->andWhere("capital_letter='" . $this->link . "'");
        }
        if ($type != null && $type != "") {
            $query = $query->addWhere('c_type = ?', $type);
            if ($sex != null && $sex != "")
                $query = $query->addWhere('sex=?', $sex);
        }

        $query = $query->orderBy('c.modify_time desc,c.celebrity_id desc');
        $this->pages = new sfDoctrinePager('Celebrity', $this->recordCount); //$this->currentPage
        $this->pages->setQuery($query); //$q   数据库查询语句
        $this->pages->setPage($this->currentPage); //
        $this->pages->init();

    }
}
